package com.example.block_chain.service.impl.classs;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.block_chain.common.ResponseResult;
import com.example.block_chain.domain.dto.Admin_ClassDto;
import com.example.block_chain.domain.pojo.AdminClass;
import com.example.block_chain.mapper.AdminClassMapper;
import com.example.block_chain.service.classs.AdminClassService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AdminClassServiceImpl implements AdminClassService {

    @Autowired
    private AdminClassMapper adminClassMapper;

    @Override
    public ResponseResult addAdmin_Class(Admin_ClassDto dto) {
        AdminClass adminClass = new AdminClass();
        BeanUtils.copyProperties(dto, adminClass);

        adminClassMapper.insert(adminClass);

        return ResponseResult.okResult();
    }

    @Override
    public List<String> getClassList(Long id) {
        LambdaQueryWrapper<AdminClass> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AdminClass::getAdminId, id);
        return adminClassMapper.selectList(queryWrapper).stream().map(AdminClass::getClassId).collect(Collectors.toList());
    }
}
